package com.ryskoo.permission.menu.domain;

import com.ryskoo.framework.core.bean.BasicPO;
import com.ryskoo.permission.permission.domain.PermissionPO;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.List;

/**
 * @author thq
 */

@Entity
@Table(name = "PMS_MENU")
public class MenuPO extends BasicPO {

    private static final long serialVersionUID = -3794558042049732986L;

    /**
     * 菜单名称
     */
    @Column(name = "name", length = 20, nullable = false)
    private String name;

    /**
     * 菜单所属类型 0-平台菜单 1-商户菜单 默认是平台菜单
     */
    @Column(name = "type", columnDefinition = "tinyint", length = 2, nullable = false)
    private int type = 0;

    /**
     * 链接地址
     */
    @Column(name = "url", length = 200)
    private String url;

    /**
     * 菜单图标
     */
    @Column(name = "icon", length = 200)
    private String icon;

    /**
     * 菜单排序
     */
    @Column(name = "position")
    private int position;

    /**
     * 父菜单编号
     */
    @Column(name = "parent_id", columnDefinition = "character", length = 32)
    private String parentId;

    /**
     * 启用状态 true为启用 false为停用 默认true
     */
    @Column(name = "state")
    private boolean state = true;

    /**
     * 菜单所属类型
     */
    @Transient
    private String typeName;

    /**
     * 启用状态
     */
    @Transient
    private String stateName;

    /**
     * 页面菜单关联的权限列表
     */
    @Transient
    private List<PermissionPO> permissionList;

    /**
     * 子菜单集合
     */
    @Transient
    private List<MenuPO> childrens = new ArrayList<MenuPO>();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public void setState(boolean state) {
        this.state = state;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }


    public boolean isState() {
        return state;
    }

    public String getTypeName() {
        return 1 == this.type ? "平台菜单" : "商户菜单";
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public String getStateName() {
        return true == this.state ? "是" : "否";
    }

    public void setStateName(String stateName) {
        this.stateName = stateName;
    }

    public List<PermissionPO> getPermissionList() {
        return permissionList;
    }

    public void setPermissionList(List<PermissionPO> permissionList) {
        this.permissionList = permissionList;
    }

    public List<MenuPO> getChildrens() {
        return childrens;
    }

    public void setChildrens(List<MenuPO> childrens) {
        this.childrens = childrens;
    }

}
